package com.ruoyi.web.controller.project.maintain;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.project.maintain.domain.ProjectMaintain;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.maintain.domain.vo.ProjectMaintainVo;
import com.ruoyi.project.maintain.domain.bo.ProjectMaintainBo;
import com.ruoyi.project.maintain.service.IProjectMaintainService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工程维护
 *
 * @author ruoyi
 * @date 2023-12-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/maintain")
public class ProjectMaintainController extends BaseController {

    private final IProjectMaintainService iProjectMaintainService;

    /**
     * 查询工程维护列表
     */
    @SaCheckPermission("project:maintain:list")
    @GetMapping("/list")
    public TableDataInfo<ProjectMaintainVo> list(ProjectMaintainBo bo, PageQuery pageQuery) {
        return iProjectMaintainService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工程维护列表
     */
    @SaCheckPermission("project:maintain:export")
    @Log(title = "工程维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ProjectMaintainBo bo, HttpServletResponse response) {
        List<ProjectMaintainVo> list = iProjectMaintainService.queryList(bo);
        ExcelUtil.exportExcel(list, "工程维护", ProjectMaintainVo.class, response);
    }

    /**
     * 获取工程维护详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:maintain:query")
    @GetMapping("/{id}")
    public R<ProjectMaintainVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iProjectMaintainService.queryById(id));
    }

    /**
     * 新增工程维护
     */
    @SaCheckPermission("project:maintain:add")
    @Log(title = "工程维护", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<ProjectMaintain> add(@Validated(AddGroup.class) @RequestBody ProjectMaintainBo bo) {
        return R.ok(iProjectMaintainService.insertByBo(bo));
    }

    /**
     * 修改工程维护
     */
    @SaCheckPermission("project:maintain:edit")
    @Log(title = "工程维护", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<ProjectMaintain> edit(@Validated(EditGroup.class) @RequestBody ProjectMaintainBo bo) {
        return R.ok(iProjectMaintainService.updateByBo(bo));
    }

    /**
     * 删除工程维护
     *
     * @param ids 主键串
     */
    @SaCheckPermission("project:maintain:remove")
    @Log(title = "工程维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iProjectMaintainService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
